package com.hntest.service.impl;

import com.hntest.dao.StudentDao;
import com.hntest.entity.Grade;
import com.hntest.entity.Pager;
import com.hntest.entity.Student;
import com.hntest.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentDao studentDao;

    @Override
    public int getCounts(Student stu) {
        return  studentDao.getCounts(stu);
    }

    @Override
    public List<Student> getListByPage(Pager pager, Student student) {
        //查询总数量
        pager.setTotalCounts(studentDao.getCounts(student));
        Map<String,Object>map = new HashMap<String,Object>();
        map.put("stu",student);
        map.put("pageStart",(pager.getCurrPage()-1)*pager.getPageSize()+1);
        map.put("pageEnd",pager.getCurrPage()*pager.getPageSize());

        List<Student> list = studentDao.getListByPage(map);
        return list;
    }

    @Override
    public List<Grade> getAllGrade() {
        return studentDao.getAllGrade();
    }

    @Override
    public int delete(int sno) {
        System.out.println("正在执行删除");
        return studentDao.delete(sno);
    }

    @Override
    public int insert(Student student) {
        System.out.println("正在执行新增");
        return studentDao.insert(student);
    }

    @Override
    public Student getStudentBySno(int sno) {
        return studentDao.getStudentBySno(sno);
    }

    @Override
    public int update(Student student) {
        System.out.println("正在执行修改");
        return studentDao.update(student);
    }
}
